package com.zfei.gfb.api.domain;

import java.io.Serializable;
import java.util.Objects;

/**
 * 收件箱元组
 *
 * @author fgh
 */
public class KeyTuple implements Serializable, Comparable<KeyTuple> {

    /**
     * 名字
     */
    private String name;

    /**
     * 类型
     */
    private String type;

    /**
     * 事件ID
     */
    private String eventId;

    /**
     * 事件时间
     */
    private Double searchNum;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public Double getSearchNum() {
        return searchNum;
    }

    public void setSearchNum(Double searchNum) {
        this.searchNum = searchNum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        KeyTuple that = (KeyTuple) o;
        return Objects.equals(name, that.name) &&
                Objects.equals(eventId, that.eventId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, eventId);
    }


    @Override
    public int compareTo(KeyTuple o) {
        return compare(this, o);
    }

    public static int compare(KeyTuple x, KeyTuple y) {
        int value = Double.compare(x.getSearchNum(), y.getSearchNum());
        if (value == 0) {
            return x.getEventId().compareTo(y.getEventId());
        }
        return value;
    }

}
